import elasticsearch7
import requests
from sqlalchemy.dialects.mssql import json

from config.secure import ES_URI, USERNAME, PASSWORD, PORT, PORT_SMALL, ES_URI_SMALL


class EsApi(object):
    server = ES_URI
    headers = {'content-type': 'application/json'}
    es = elasticsearch7.Elasticsearch([ES_URI_SMALL], http_auth=(USERNAME, PASSWORD), port=PORT_SMALL)

    @classmethod
    def deleteLocalIndex(cls, order_number):
        if not order_number or order_number == '':
            return
        headers = {'content-type': 'application/json'}
        res = requests.delete(f'{ES_URI_SMALL}:{PORT_SMALL}' + f'/{order_number}?pretty', headers=headers,
                              auth=(USERNAME, PASSWORD))
